#ifndef IMG_FILE_H
#define IMG_FILE_H

#include <QDebug>
#include <QObject>
#include <QProcess>
#include <QFileInfo>

#include <vtkSmartPointer.h>

#include <vtkNIFTIImageReader.h>
#include <vtkNIFTIImageHeader.h>
#include <vtkNIFTIImageWriter.h>
#include <vtkTransform.h>
#include <vtkImageReslice.h>

#include <vtkImageData.h>

#include "sys_data.h"

struct img_WL {
public:
    QString name;
    double window{0.0}, level{0.0};
    img_WL() {}
    img_WL(QString _name, double _window, double _level)
        : name(_name)
        , window(_window)
        , level(_level) {}
};

struct img_Info {
    static QMap<int, QString> DATA_TYPE;
    static QMap<int, QString> UNIT;
    static QMap<int, img_WL> IMG_WL;
    QString fileName;
    qint64 fileSize;
    int dimInfo;
    short dim[8];
    double pixdim[8];
    int voxOffset;
    int dataType;
    int bitPix;
    double sclSlope, sclInter;
    QString descrip;
    QString auxFile;
    short qFormCode, sFormCode;
    double qOffset[3];
    double srow[3][4];
    int xyzt_units;
    const QString toQString()const;
};

class img_File: QObject
{

    Q_OBJECT

private:
    bool OPENED_FLAG;
    QString name;
    img_Info fileInfo;
    double window{2310}, level{134};
    vtkSmartPointer<vtkImageData> imgData;
    vtkSmartPointer<vtkNIFTIImageHeader> imgHeader;
    vtkSmartPointer<vtkNIFTIImageReader> fileReader;

    void setFileInfo();
    void covDCMFile(const QString &filePath);
    void readFile(const QString &fileName);

public:
    explicit img_File(const QString &fileName = "", QObject * parent = nullptr);
    ~img_File();
    void openFile(const QString &fileName);

    //getter
    img_Info const & info()const;
    vtkImageData * const image();
    vtkNIFTIImageReader * const reader()const;
    vtkNIFTIImageHeader * const header()const;
    QString const & getFileName()const;
    double getWindow() const;
    double getLevel() const;
    bool isOpen()const;

    //clear
    void clear();
};

#endif // IMG_FILE_H
